package my.soft.aiteacher.teacher.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import my.soft.aiteacher.common.mapper.VideoInformationMapper;
import my.soft.aiteacher.common.service.IVideoInformationService;
import my.soft.aiteacher.teacher.mapStruct.CoursesMapStructs;
import my.soft.aiteacher.teacher.pojo.CoursesDo;
import my.soft.aiteacher.teacher.mapper.CoursesMapper;
import my.soft.aiteacher.teacher.pojo.CoursesVo;
import my.soft.aiteacher.teacher.service.ICoursesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author GMCX
 * @since 2025-06-14
 */
@Service
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, CoursesDo> implements ICoursesService {

    @Resource
    private CoursesMapper coursesMapper;
    @Resource
    private CoursesMapStructs coursesMapStructs;
    @Resource
    private VideoInformationMapper videoInformationMapper;
    @Override
    public void createCourse(CoursesVo coursesVo) {
        if(Objects.isNull(coursesVo.getUserId())){
            throw new RuntimeException("不存在教师信息");
        }

        if(coursesVo.getStartDate().isBefore(coursesVo.getEndDate())){
            throw new RuntimeException("开课时间不能大于结束时间");
        }
        coursesMapper.insert(coursesMapStructs.toDo(coursesVo));
    }

    @Override
    public void updateCourse(CoursesVo coursesVo) {
        if(Objects.isNull(coursesVo.getUserId())){
            throw new RuntimeException("不存在教师信息");
        }

        if(coursesVo.getStartDate().isBefore(coursesVo.getEndDate())){
            throw new RuntimeException("开课时间不能大于结束时间");
        }
        coursesMapper.updateById(coursesMapStructs.toDo(coursesVo));
    }
}
